package com.transfiguro;

import com.transfiguro.datamodel.csmodels.CSClassModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * This class provides methods to write a given {@link CSClassModel} to a .cs file
 */
public class Writer {
    private final Logger logger = LoggerFactory.getLogger(Writer.class);
    private FileWriter csFile;
    private CSClassModel csClassModel;

    /**
     * Constructor
     *
     * @param csClassModel  The <code>CSClassModel</code> to be written to a file
     */
    public Writer(final CSClassModel csClassModel) {
        this.csClassModel = csClassModel;
    }


    /**
     * This method writes the <code>CSClassModel</code> to a file
     */
    public void writeFile() {
        try {
            csFile = new FileWriter("/Users/karunr/Desktop/outputcs/" + csClassModel.getClassName() + ".cs");
            BufferedWriter out = new BufferedWriter(csFile);
            out.write(csClassModel.toString());
            out.close();
        } catch (final IOException e) {
            logger.debug("Exception: {}", e.getMessage());
        }


    }
}
